//此test是笔试强训前三天内容，以后天数内容会一天一test
#pragma GCC diagnostic error "-std=c++11"
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

void Written_test_train_1()
{

    int x = 3, y = 3;
    switch(x % 2)
    {
        case 1:
            switch(y)
            {
                case 0:
                    cout << "first";
                case 1:
                    cout << "second";
                default:
                    cout << "hello";
            }
        case 2:
            cout << "third";
    }
}

void Written_test_train_2()
{
    string s1;
    string s2;
    string s3;
    cout<< "请输入字符串";
    cin >> s1;
    int i = 0;
    for(i = 0; i <= s1.size() ;++i)
    {
        if(s1[i] >= '0' && s1[i] <= '9')
        {
            s3 += s1[i];
        }
        else 
        {
            if(s2.size() < s3.size())
            {
                s2 = s3;
            }
            else 
            {
                s3.clear();
            }
        }
    }
    cout << s2 << endl;
}

void Written_test_train_3()
{
    vector<int> numbers;
    numbers.push_back(1);
    numbers.push_back(2);
    numbers.push_back(3);
    numbers.push_back(2);
    numbers.push_back(2);
    numbers.push_back(2);
    numbers.push_back(5);
    numbers.push_back(4);
    numbers.push_back(2);
    numbers.push_back(6);
    numbers.push_back(2);
    numbers.push_back(2);
    numbers.push_back(2);
    if(numbers.empty())
    {
        cout << 0 << endl;;
    }
    numbers.push_back(1);

    sort(numbers.begin(), numbers.end());
    int middle = numbers[numbers.size()/2];
    int i = 0;
    int count = 0;
    for(i = 0 ;i < numbers.size();i++)
    {
        if(numbers[i] == middle)
            ++count;
    }

    if(count > numbers.size()/2)
    {
        cout <<"数组中存在出现次数超过一半的数字:"<< middle << endl;
    }
    else 
    {
        cout << 0 << endl;
    }
}

void Written_test_train_4()
{
    int n;
    while(cin >> n)
    {
        long long sum = 0;
        vector<int> a;
        a.resize(3*n);
        int i = 0;
        for(i = 0; i < (3 * n); ++i)
        {
            cin >> a[i];
        }
        std::sort(a.begin(),a.end());
        int j = 0;
        for(j = 0; j < n; ++j)
        {
            sum += a[a.size() - 2*(j+1)];
        }
        cout << sum << endl;
    }
}

void Written_test_train_5()
{
    string str1;
    string str2;
    getline(cin,str1);
    getline(cin,str2);
    int hashtable[256] = {0};
    int i = 0;
    for(i = 0;i<str2.size();i++)
    {
        hashtable[str2[i]]++;
    }
    string ret;
    int j = 0;
    for(j = 0;j < str1.size();j++)
    {
        if(hashtable[str1[j]] == 0)
        {
            ret += str1[j];
        }
    }
    cout << ret << endl;
}

void Written_test_train_6()
{
    int n;
    cin >> n;
    vector<int> a;
    a.resize(n + 1);
    a[n] = 0;
    int i = 0;
    for(i = 0;i < n;++i)
    {
        cin >> a[i];
    }
    int j = 0;
    int count = 0;
    while(j < n)
    {
        if(a[j] < a[j + 1])
        {
            while(j < n && a[j] <= a[j + 1])
                j++;
            count++;
            j++;
        }
        else if(a[j] == a[j + 1])
            j++;
        else 
        {
            while(j < n && a[j] >= a[j + 1])
                j++;
            count++;
            j++;
        }
    }
    cout << count << endl;
}

//倒置字符串
void Written_test_train_7()
{
    string s;
    getline(cin,s);
    reverse(s.begin(),s.end());
    auto start = s.begin();
    while(start != s.end())
    {
        auto start_copy = start;
        while(*start_copy != ' ' &&  start_copy != s.end())
            start_copy++;

        reverse(start,start_copy);

        if(start_copy != s.end())
            start = start_copy + 1;
        else 
            start = start_copy;
    }
    cout << s << endl;
}
int main()
{
    //Written_test_train_1();
    //Written_test_train_2();//寻找字符串中最长的数字字符
    //Written_test_train_3();//寻找串中出现超过一半的数字
    //Written_test_train_4();//本题主要运用了贪心算法
    //Written_test_train_5();
    //Written_test_train_6();//排序子序列
    Written_test_train_7();//倒置字符串
    return 0;
}
